#!/usr/bin/perl -w

$path='/org/lists.debian.org/archive-spam-removals/spam-removals/reports';

opendir(DIR, $path) or die ("$0: can't open $path for reading: $!\n");
@files = grep { /report$/ && -f "$path/$_" } readdir(DIR);
closedir DIR;

foreach $report (@files) {
  $time = (stat("$path/$report"))[9];
  $user = (split(/\./, $report))[0];
  open (REPORT, "$path/$report") or die ("$0: can't open $path/$report for reading: $!\n");
  foreach $line (<REPORT>) {
    if ($line =~ m#^\s*(spam|not spam|non spam|inappropriate|unknown|unchecked);([-\w]+);(\d+);(\d+);(\d+);\d+;\S+\s*$#) {
      $rating = 'Spam' if $1 eq 'spam';
      $rating = 'Ham' if $1 eq 'not spam';
      $rating = 'Ham' if $1 eq 'non spam';
      $rating = 'Inappropriate' if $1 eq 'inappropriate';
      next if ($1 eq 'unknown') or ($1 eq 'unchecked');
      
      $article = sprintf("msg%05d.html", $5);
      printf "time: %d; addr: 127.0.0.2; list: %s, date: %d/%02d, msg: %s, rating: $rating, reviewer: $user\n", $time, $2, $3, $4, $article, $rating, $user;
    } else {
#      print "debug: $line";
    }
  }
  close (REPORT);
}

#  
